/**
 * 
 */
$(function(){
	adaptive();
	renderICkeck();
	pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'/ietm/annotations'},{projectId:top.projectId},$("#path").val());
	//注释搜索
	$('#anno-search').click(function(){
		//if($('#anno-search-field').val()!=="")
		 $("#frameReft").load(encodeURI("/ietm/annotations?content="+$('#anno-search-field').val()+"&projectId="+top.projectId+"&random="+Math.random()));
		 //$('#pagination').jqPaginator(pagination({total:parseInt($("#total").val()),size:parseInt($("#size").val()),currentpage:parseInt($("#page").val()),visibPage:3,pagePath:'annotations'}));

	});
	//书签搜索
	$('#tag-search').click(function(){
		if($('#tag-search-field').val()!=="")
		 $("#frameReft").load(encodeURI("/ietm/tags?title="+$('#tag-search-field').val()+"&projectId="+top.projectId+"&random="+Math.random()));
	});
	
	/*$('#annotations-upload').click(function(e){
        e.preventDefault();
        var diag = new $.Zebra_Dialog({
            source: {'iframe': {
                'src':'/ietm/annotations/getObject?page=annotations-upload',
                'height':80,
            }},
            width:400,
            title:'上传附件',
            buttons: ['确定']
        });
    });*/
	
	$('#annotations-export').click(function(e){
		window.location.href="/file/xls/export";
	});
	$('#annotations-upload').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'annotations-upload-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=annotations-upload" ,
					'height' : 300
				}
			},
			width : 600,
			title : '上传附件',
		    buttons:  [
	               {caption: '上传', callback: function() {
	            	   $("#annotations-upload-diag").contents().find("#annoations-upload-form").submit();
	            	   $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">上传成功!</div></div>', {
    			            'title':'提示',
    			            'buttons':[{caption: '确定',callback:function(){
    			            	  $("#frameReft").load("/ietm/annotations?random="+Math.random());
    			            }}]
    			         });
    		    	  
	            	  
	                  }}
                    ]
		});
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	$('#annotations-del-upload').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		 $.ajax({
		     type: "post",
		     dataType: "text",
		     url:'/ietm/annoations/delFile?id='+id,
		     success: function (data, status) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		    	 $("#frameReft").load("/ietm/annotations?random="+Math.random());
		     },
		     error: function (data) {
		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
			            'title':'提示',
			            'buttons':['确定']
			         });
		     }
		 });
	}});
	
	
	
	//注释编辑
	$('#annotations-edit').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'annotations-edit-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=annotations-edit" ,
					'height' : 300
				}
			},
			width : 600,
			title : '编辑',
		    buttons:  [
		               {caption: '保存', callback: function() {
		            	   $("#annotations-edit-diag").contents().find("#editForm").submit();
		            	   $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
	    			            'title':'提示',
	    			            'buttons':[{caption: '确定',callback:function(){
	    			            	  $("#frameReft").load("/ietm/annotations?random="+Math.random());
	    			            }}]
	    			         });
	    		    	  
		            	  
		                  }}
                        ]
		});
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	//注释编辑
	$('#nav-annotations-edit').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'annotations-edit-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=annotations-edit" ,
					'height' : 300
				}
			},
			width : 600,
			title : '编辑',
		    buttons:  [
		               {caption: '保存', callback: function() {
		            	   $("#annotations-edit-diag").contents().find("#editForm").submit();
		            	   $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
	    			            'title':'提示',
	    			            'buttons':[{caption: '确定',callback:function(){
	    			            	//window.parent.frames[].bottom.location.reload();nav-annoations-dialog
	    			            	window.location.reload();
	    			            }}]
	    			         });
	    		    	  
		            	  
		                  }}
                        ]
		});
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	
	//注del
	
	$('#annotations-del').on('click', function(e) {
		e.preventDefault();
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var ids=checkBoxs.parent().parent().find("[name='id']");
	    var  id="";
		   for (var i=0;i<ids.length;i++)
		{
				if(i<ids.length-1){
					id += $(ids[i]).text()+",";
				}else{
					id += $(ids[i]).text();
				}
		} 
		   
		 $.ajax({
	     type: "post",
	     url:"/ietm/commentTags/delete" ,
	     data:{id:id},
	     success: function (data, status) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	    	 $("#frameReft").load("/ietm/annotations?random="+Math.random());
	     },
	     error: function (data) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	     }
	 });
		   
	 });
	
	$('#nav-annotations-del').on('click', function(e) {
		e.preventDefault();
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var ids=checkBoxs.parent().parent().find("[name='id']");
	    var  id="";
		   for (var i=0;i<ids.length;i++)
		{
				if(i<ids.length-1){
					id += $(ids[i]).text()+",";
				}else{
					id += $(ids[i]).text();
				}
		} 
		   
		 $.ajax({
	     type: "post",
	     url:"/ietm/commentTags/delete" ,
	     data:{id:id},
	     success: function (data, status) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	    	 window.location.reload();
	    	 top.$("#publiciframe").attr('src',top.$("#publiciframe").attr('src'));
	     },
	     error: function (data) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	     }
	 });
		   
	 });
	//书签
	$('#tags-edit').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'tags-edit-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=tags-edit" ,
					'height' : 300
				}
			},
			width : 600,
			title : '编辑',
		    buttons:  [
		               {caption: '保存', callback: function() { 
		            	     $.ajax({
		            	    	    url:  '/ietm/commentTags/saveOrUpdate',
		            	            type: 'post',
		            	            data: $("#tags-edit-diag").contents().find("#editForm").serializeObject(),
					    		    success: function (data) {
					    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
					    			            'title':'提示',
					    			            'buttons':['确定']
					    			         });
					    		    	 $("#frameReft").load("/ietm/tags?random="+Math.random());
					    		    	// $("#frameReft").load("/ietm/project?random="+Math.random());
					    		     },
					    		     error: function (data) {
					    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
					    			            'title':'提示',
					    			            'buttons':['确定']
					    			         });
					    		     }
		            	        });
		                  }}
                        ]
		});
		
		
		
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	
	$('#nav-tags-edit').click(function(e) {		
		e.preventDefault();
	if($('input[name="select_item"]:checked').length==1){
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var id=checkBoxs.parent().parent().find("[name='id']").text();
		var diag = new $.Zebra_Dialog({
			source : {
				'iframe' : {
					'id':'tags-edit-diag',
					'src':'/ietm/annotations/getObject?id='+id+"&page=tags-edit" ,
					'height' : 300
				}
			},
			width : 600,
			title : '编辑',
		    buttons:  [
		               {caption: '保存', callback: function() { 
		            	     $.ajax({
		            	    	    url:  '/ietm/commentTags/saveOrUpdate',
		            	            type: 'post',
		            	            data: $("#tags-edit-diag").contents().find("#editForm").serializeObject(),
					    		    success: function (data) {
					    		    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功!</div></div>', {
					    			            'title':'提示',
					    			            'buttons':['确定']
					    			         });
					    		    	 window.location.reload()
					    		     },
					    		     error: function (data) {
					    		    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">保存失败!</div></div>', {
					    			            'title':'提示',
					    			            'buttons':['确定']
					    			         });
					    		     }
		            	        });
		                  }}
                        ]
		});
		
		
		
	}else{
		 $.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">请选中一行!</div></div>', {
	            'title':'提示',
	            'buttons':['确定']
	         });
	}});
	//书签删除
	$('#tags-del').on('click', function(e) {
		e.preventDefault();
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var ids=checkBoxs.parent().parent().find("[name='id']");
	    var  id="";
		   for (var i=0;i<ids.length;i++)
		{
				if(i<ids.length-1){
					id += $(ids[i]).text()+",";
				}else{
					id += $(ids[i]).text();
				}
		} 
		   
		 $.ajax({
	     type: "post",
	     url:"/ietm/commentTags/delete" ,
	     data:{id:id},
	     success: function (data, status) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	    	 $("#frameReft").load("/ietm/tags?random="+Math.random());
	     },
	     error: function (data) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	     }
	 });
		   
	 });
	
	
	//书签删除
	$('#nav-tags-del').on('click', function(e) {
		e.preventDefault();
		var checkBoxs= $('input[name="select_item"]:checked').parent();
		var ids=checkBoxs.parent().parent().find("[name='id']");
	    var  id="";
		   for (var i=0;i<ids.length;i++)
		{
				if(i<ids.length-1){
					id += $(ids[i]).text()+",";
				}else{
					id += $(ids[i]).text();
				}
		} 
		   
		 $.ajax({
	     type: "post",
	     url:"/ietm/commentTags/delete" ,
	     data:{id:id},
	     success: function (data, status) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">删除成功!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	    	 window.location.reload();
	    	// $("#frameReft").load("/ietm/nav-tags?random="+Math.random());
	     },
	     error: function (data) {
	    	 $.Zebra_Dialog('<div class="prompt"><div class="error-icon"></div><div class="success-title">删除失败!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
	     }
	 });
		   
	 });
	
});
//
function dw(p){
	
	changeMain('ietm-home?comment');
	top.dmIds=$(p).attr('dmId');
	top.posY=$(p).attr('posY');
	top.posYs=$(p).attr('posY');
	// $(document).unbind('.Zebra_Dialog');
     //$(window).unbind('.Zebra_Dialog');
	window.parent.clickDw($(p).attr('dmId'));
	window.parent.closeDailog();
	
}